﻿using System;
using System.Collections.Generic;
using System.Windows.Forms;
using XDesigner.ORM ;
using 刘颜红销售项目管理.Business.DOM;
using 刘颜红销售项目管理.Business;
using XDesigner.AppFramework;

namespace 刘颜红销售项目管理
{
    static class Program
    {
        /// <summary>
        /// 应用程序的主入口点。
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            if (System.IO.File.Exists(AppSettings.Default.DBFileName) == false)
            {
                MessageBox.Show(null , "请指定一个数据库文件!", "系统提示");
                using (dlgConfig dlg = new dlgConfig())
                {
                    if (dlg.ShowDialog() == DialogResult.Cancel)
                    {
                        return;
                    }
                }
            }
            frmStart frm = new frmStart();
            frm.Show();
            frm.Update();
            MyApplicationFramework.Instance.ORMEngine.Config.DebugMode = true;
            MyApplicationFramework.Instance.ORMEngine.Config.BufferLevel = ORMBufferLevel.Both;
            MyApplicationFramework.Instance.ORMEngine.Config.UpdateImmediately = true;
            
            MyApplicationFramework.Instance.ORMEngine.DataBase.Connection = CreateConnection();

            //MessageBox.Show(System.Environment.TickCount.ToString()); return;
            frmMain mf = new frmMain();
            frm.Owner = mf;
            mf.Show();
            frm.Close();
            Application.Run( mf );
            //Application.Run(new Form1());
        }


        public static System.Data.IDbConnection CreateConnection()
        {
            System.Data.OleDb.OleDbConnection conn = new System.Data.OleDb.OleDbConnection();
            //conn.ConnectionString = Properties.Settings.Default.MainConnectionString;
            conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\"" + AppSettings.Default.DBFileName + "\"";
            return conn;
        }
 
    }
}